package com.meteor.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.meteor.pojo.Blog;
import com.meteor.pojo.Type;
import com.meteor.service.BlogService;
import com.meteor.service.TypeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class TypeController {

    @Resource
    private TypeService typeService;

    @Resource
    private BlogService blogService;

    @GetMapping("/types")
    public String types(Model model) {
        List<Type> list = typeService.list();
        model.addAttribute("types",list);
        return "types";
    }

    //通过标签查询博客
    @GetMapping("/byType/{id}")
    public String type(@PathVariable Integer id,Model model) {
        LambdaQueryWrapper<Blog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Blog::getTypeId, id);
        List<Blog> list = blogService.list(queryWrapper);
        List<Type> types = typeService.list();
        model.addAttribute("types",types);
        model.addAttribute("blogs", list);
        model.addAttribute("code", 1);
        return "types";
    }
}














